package cn.jinshengda.controller;


import cn.jinshengda.entity.Department;
import cn.jinshengda.entity.Position;
import cn.jinshengda.service.DepartmentService;
import cn.jinshengda.service.PositionService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-01-08
 */
@RestController
@CrossOrigin
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;
    @Autowired
    private PositionService positionService;

    @GetMapping("department/queryAll")
    public List<Department> queryAllDept(){
        List<Department> list = departmentService.list(null);
//        for (Department department : list) {
//            QueryWrapper<Position> queryWrapper=new QueryWrapper<>();
//            queryWrapper.eq("department_id", department.getId());
//            List<Position> positions = positionService.list(queryWrapper);
//            department.setPositions(positions);
//        }
        return list;
    }

    @GetMapping("department/{id}")
    public Department queryById(@PathVariable Integer id){
        Department department = departmentService.getById(id);
        return department;

    }


}

